import { IFormInput } from "./Components/input/types";
import { IFormTextArea } from "./Components/textarea/types";
import { IFormSelect } from "./Components/select/types";
import { IFormMultiple } from "./Components/multiple/types";
import { IFormPopCheck } from "./Components/popCheck/types";
import { IFormUpload } from "./Components/upload/types";
import { IFormLink } from "./Components/link/types";
import { IFormArea } from "./Components/area/types";
import { IFormSwitch } from "./Components/switch/types";
import { IFormTimePicker } from "./Components/timePicker/types";
import { IFormCalendar } from "./Components/calendar/types";
import { IFormUserIconUpload } from "./Components/usericonupload/types";
import { IFormUploadPopup } from "./Components/uploadPopup/types";

export type IFormRulesRequired = {
  required?: boolean;
  message?: string;
};

export type IFormRulesRegular = {
  regular: RegExp;
  message?: string;
};

type IFormRules = IFormRulesRequired | IFormRulesRegular;

export type IFormItem = IFormData & {
  layer?: "horizontal" | "vertical";
  label: string;
  key?: string;
  readonly?: boolean;
  rules?: IFormRules[];
};

export type IFormData =
  | IFormInput
  | IFormTextArea
  | IFormSelect
  | IFormMultiple
  | IFormPopCheck
  | IFormUpload
  | IFormLink
  | IFormArea
  | IFormSwitch
  | IFormTimePicker
  | IFormCalendar
  | IFormUserIconUpload
  | IFormUploadPopup;

export type ITypeSetLayers = (value: "horizontal" | "vertical") => void;

export interface IFormTypeData {
  label: string;
  value: string;
}

interface IFormResult {
  result: object;
  error: object;
  submitState?: boolean;
}

export type IFormSubmitCallBack = (data: IFormResult) => void;

export interface IFormRef {
  submit(
    data: IFormSubmitCallBack | undefined,
    isFormGroup?: boolean
  ): Promise<IFormResult>;
  submit(data: IFormSubmitCallBack): Promise<IFormResult>;
}
